package com.ruoyi.voucher.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.voucher.mapper.SummaryMapper;
import com.ruoyi.voucher.domain.Summary;
import com.ruoyi.voucher.service.ISummaryService;

/**
 * 摘要管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-02-21
 */
@Service
public class SummaryServiceImpl extends ServiceImpl<SummaryMapper,Summary> implements ISummaryService
{
    @Autowired
    private SummaryMapper summaryMapper;

    /**
     * 查询摘要管理
     * 
     * @param id 摘要管理主键
     * @return 摘要管理
     */
    @Override
    public Summary selectSummaryById(Long id)
    {
        return summaryMapper.selectSummaryById(id);
    }

    /**
     * 查询摘要管理列表
     * 
     * @param summary 摘要管理
     * @return 摘要管理
     */
    @Override
    public List<Summary> selectSummaryList(Summary summary)
    {
        return summaryMapper.selectSummaryList(summary);
    }

    /**
     * 新增摘要管理
     * 
     * @param summary 摘要管理
     * @return 结果
     */
    @Override
    public int insertSummary(Summary summary) throws Exception {
        QueryWrapper<Summary> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(Summary::getSummary,summary.getSummary());
        Summary selectOne = summaryMapper.selectOne(wrapper);
        if (selectOne != null){
            throw new Exception("不可录入重复相同摘要");
        }
        return summaryMapper.insert(summary);
    }

    /**
     * 修改摘要管理
     * 
     * @param summary 摘要管理
     * @return 结果
     */
    @Override
    public int updateSummary(Summary summary) throws Exception {
        QueryWrapper<Summary> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(Summary::getSummary,summary.getSummary());
        Summary selectOne = summaryMapper.selectOne(wrapper);
        if (selectOne != null){
            throw new Exception("不可录入重复相同摘要");
        }
        return summaryMapper.updateById(summary);
    }

    /**
     * 批量删除摘要管理
     * 
     * @param ids 需要删除的摘要管理主键
     * @return 结果
     */
    @Override
    public int deleteSummaryByIds(Long[] ids)
    {
        return summaryMapper.deleteSummaryByIds(ids);
    }

    /**
     * 删除摘要管理信息
     * 
     * @param id 摘要管理主键
     * @return 结果
     */
    @Override
    public int deleteSummaryById(Long id)
    {
        return summaryMapper.deleteSummaryById(id);
    }
}
